﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using MySQL.Db;
using NLog;

namespace Gollie.Mail
{
	public class EMailCollection : Collection<EMail>
	{
		private static readonly Logger logger = LogManager.GetCurrentClassLogger();

		public void DoQueue()
		{
			try
			{
				logger.Debug("Queueing {0} mails", this.Count);

				QueryCollection queries = new QueryCollection(GollieDb.GollieMail);

				foreach (EMail email in this)
					queries.Add(email.DoQueueBatch());

				logger.Debug("Start queue mailcollection...");
				queries.Execute();
				logger.Debug("End queue mailcollection...");

			}
			catch (Exception e)
			{
				logger.FatalException("", e);

				throw;
			}
		}
	}
}
